package com.giaothong.ui;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONObject;

import android.app.AlertDialog;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.location.LocationManager;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.provider.Settings;
import android.text.Html;
import android.util.Log;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;

import com.giaothong.R;
import com.giaothong.config.Define;
import com.giaothong.config.Define.StoreAcount;
import com.giaothong.controller.GoogleApiController;
import com.giaothong.controller.LocationController;
import com.giaothong.customview.DisplayDirectionView;
import com.giaothong.customview.MenuMainView;
import com.giaothong.customview.StepDirectionView;
import com.giaothong.customview.adapter.ListLocationAdapter;
import com.giaothong.customview.custommapview.OnSingleTapListener;
import com.giaothong.customview.custommapview.TapControlledMapView;
import com.giaothong.customview.overlay.MapOverlayDrawLine;
import com.giaothong.customview.overlay.SimpleItemizedOverlay;
import com.giaothong.db.SharePreferenceAdapter;
import com.giaothong.db.table.DtbLikeLocation;
import com.giaothong.http.core.HttpAsyncCallback;
import com.giaothong.http.core.HttpConnectionId;
import com.giaothong.http.core.HttpResult;
import com.giaothong.model.ModelGetDirectionTwoLocationRequests;
import com.giaothong.model.ModelGetListLocationStatusRequest;
import com.giaothong.model.ModelGetLocationInfoGoogleApiRequest;
import com.giaothong.model.ModelSendLocationStatusRequest;
import com.giaothong.model.entity.LocationSearchEntity;
import com.giaothong.model.entity.LocationStatus;
import com.giaothong.utils.ALog;
import com.giaothong.utils.DialogUtil;
import com.giaothong.utils.DialogUtil.DialogOnClickListener;
import com.giaothong.utils.MyLocationOverlayCustom;
import com.giaothong.utils.SessionData;
import com.giaothong.utils.ToastUtils;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.Overlay;
import com.google.android.maps.OverlayItem;

public class MainMapActivity extends MapActivity implements HttpAsyncCallback<JSONObject> {

	private static final int REQUEST_FROM_LIKE_LOCATION = 0;
	private static final int REQUEST_FROM_SEARCH_LOCATION = 1;

	private final int SHOW_TAP_LOCATION = 1;                   // message show tap location
	private final int SEARCH_LOCATION = 2; // message show tap location
	private MyLocationOverlayCustom myLocationOverlay; // store info for
														// MyLocation
	public TapControlledMapView mapView;
	private List<Overlay> mapOverlays;

	private SimpleItemizedOverlay itemizedOverlayUnderConstruction;                 // init Under Construction Overlay   
	private SimpleItemizedOverlay itemizedOverlayTrafficJams_5; // init traffic
																// jams Overlay
	private SimpleItemizedOverlay itemizedOverlayTrafficJams_10;
	private SimpleItemizedOverlay itemizedOverlayTrafficJams_20;
	private SimpleItemizedOverlay itemizedOverlayTrafficJams_30;
	private SimpleItemizedOverlay itemizedOverlayTrafficJams_40;
	private SimpleItemizedOverlay itemizedOverlayTrafficLight; // hien thi mat
																// tin hieu giao
																// thong
	private SimpleItemizedOverlay itemizedOverlayPolice; // hien thi co canh sat
	private SimpleItemizedOverlay itemizedOverlayAccident; // hien thi tai nan
															// giao thong
	private SimpleItemizedOverlay itemizedOverlayNewMask;                           // init new mask Overlay Location
	private SimpleItemizedOverlay itemizedOverlayDirectionStep; // hien thi step
																// direction
	private SimpleItemizedOverlay itemizedOverlayDirectionStartEnd;
	private DisplayDirectionView bottomDirection; // hien thi ket qua
														// direction
	private StepDirectionView stepDisplayDirection;
	private MenuMainView menuMain;
	
	private boolean mask = false;            // if mask == true then selected new location else nothing...
	private boolean maskReportLocation = false, maskNavigation = false;
	private View layoutNavigation;
	ModelGetLocationInfoGoogleApiRequest modelGetLocationInfoGoogleApiRequest;
	private GeoPoint startLocation, endLocation;
	private int currentViewIdNavication;
	private EditText edtEnd, edtStart;
	private ProgressDialog progressDialog = null;
	private LocationSearchEntity indexTapLocationEntity;
	private MapOverlayDrawLine mapOverlay; // luu tru duong di khi chon duong
	SharePreferenceAdapter sharePreferenceAdapter = SharePreferenceAdapter.getInstance();

	private boolean isUpdateLocationStatus = false;

	@Override
	public void onCreate(Bundle savedInstanceState) {

		super.onCreate(savedInstanceState);
		setContentView(R.layout.layout_main);

		sharePreferenceAdapter.init(this);

		mapView = (TapControlledMapView) findViewById(R.id.mapview);

		// set MapView onListener
		setMapViewListener();

		setDisplayMap();

		// Add the zoom controls for the map
		mapView.setBuiltInZoomControls(true);
		mapView.getController().setZoom(Define.ZOOM_MAP);// Set the zoom level

		myLocationOverlay = new MyLocationOverlayCustom(getResources().getDrawable(R.drawable.marker2), mapView, this);

		mapOverlays = mapView.getOverlays();

		init();

		// show MyLocation hie tai dang comment bo phan nay
		// showMyLocation();
		mapOverlays.add(myLocationOverlay);// Add the overlay thay cho comment o
											// tren
		
		// init Overlay
		initOverLay();
		
		// set Location Overlay
		setDataInfoLocation();
		
	}


	/**
	 * set Display mapview
	 */
	private void setDisplayMap() {
		// The default view for the map will be the standard view
		if (SessionData.isSatellite())
			mapView.setSatellite(true);
		else
			mapView.setSatellite(false);
		if (SessionData.isStreet())
			mapView.setStreetView(true);
		else
			mapView.setStreetView(false);
		if (SessionData.isTraffic())
			mapView.setTraffic(true);
		else
			mapView.setTraffic(false);
	}

	@Override
	public void onResume() {
		super.onResume();
		myLocationOverlay.enableMyLocation();
		if (SessionData.isGPS() && !myLocationOverlay.getmLocationManager().isProviderEnabled(LocationManager.GPS_PROVIDER)) {
			showSettingsAlert();
		}
	}

	@Override
	public void onPause() {
		super.onPause();
		myLocationOverlay.disableMyLocation();
	}

	/**
	 * recver message and handler
	 */
	private Handler handler = new Handler() {
		@Override
		public void dispatchMessage(Message msg) {
			super.dispatchMessage(msg);
			switch (msg.what) {

			// show tap in new location selected
			case SHOW_TAP_LOCATION: {
				itemizedOverlayNewMask.onTap(0);
				animationToLocation(itemizedOverlayNewMask.getItem(0).getPoint());
			}
				break;
			case SEARCH_LOCATION: {
				/**
				 * search location from GeoPoint
				 */
				GoogleApiController.searchLocationFromGeoPoint(MainMapActivity.this, MainMapActivity.this, (GeoPoint) msg.obj, Define.RADIUS_SEARCH_LOCATION, "");
			}
				break;

			default:
				break;
			}

		}
	};

	/**
	 * overide BackKey
	 */
	@SuppressWarnings("deprecation")
	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		// if key back
		ALog.d("SDK", android.os.Build.VERSION.SDK + "");
		if (Integer.parseInt(android.os.Build.VERSION.SDK) < 5 && keyCode == KeyEvent.KEYCODE_BACK) {
			onBackPressed();
			return true;
		} else if (keyCode == KeyEvent.KEYCODE_MENU) {
			if (menuMain.getVisibility() == View.VISIBLE) {
				menuMain.setVisibility(View.GONE);
			} else {
				menuMain.setVisibility(View.VISIBLE);
			}
			return true;
		} else {
			return super.onKeyDown(keyCode, event);
		}

	}

	@Override
	public void onBackPressed() {
		if (layoutNavigation.getVisibility() == View.VISIBLE) {
			// an bang set chon duong
			layoutNavigation.setVisibility(View.GONE);
		} else if (menuMain.getVisibility() == View.VISIBLE) {
			// an menu
			menuMain.setVisibility(View.GONE);
		} else if (stepDisplayDirection.getVisibility() == View.VISIBLE) {
			// an hien thi chon duong
			stepDisplayDirection.setVisibility(View.GONE);
			bottomDirection.setVisibility(View.GONE);
			mapOverlays.remove(mapOverlay);
			itemizedOverlayDirectionStartEnd.clearAll();
			itemizedOverlayDirectionStep.clearAll();
			mapView.invalidate();
		} else
		onClickBackTopbar();
	}

	/**
	 * Back Activity
	 */
	public void onClickBackTopbar() {
		// if login then
		if (!SessionData.getUserId().equals("")) {
		DialogUtil.showConfirmDialog(this, R.string.exit_app, R.string.you_wan_to_exit, new DialogUtil.ConfirmDialogOnClickListener() {

			public void onOKButtonOnClick() {
				// exit app
				Intent setIntent = new Intent(Intent.ACTION_MAIN);
				setIntent.addCategory(Intent.CATEGORY_HOME);
				startActivity(setIntent);
			}

			public void onCancelButtonOnClick() {
				// nothing...
			}
		});
		} else {
			finish();
		}
	}

	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		// Result from confirm screen
		if (resultCode == RESULT_OK) {
			switch (requestCode) {
			case REQUEST_FROM_SEARCH_LOCATION:
				// action navigation
				if (data.getIntExtra(SearchLocationActivity.EXTRA_ACTION, R.string.dan_duong_den_day) == R.string.dan_duong_den_day) {
					GoogleApiController.getDirection(MainMapActivity.this, MainMapActivity.this, myLocationOverlay.getMyLocation(), SessionData.locationSearchEntity.getGeoPoint(), Define.METHOD_NAVIGATION, Define.SENSOR);
				} else if (data.getIntExtra(SearchLocationActivity.EXTRA_ACTION, R.string.dan_duong_den_day) == R.string.show_in_map) {
					// show in map
					// if mask location
					indexTapLocationEntity = SessionData.locationSearchEntity;
					showNewLocation(indexTapLocationEntity);
				}
				break;

			case REQUEST_FROM_LIKE_LOCATION:
				// action navigation
				if (data.getIntExtra(LikedLocationActivity.EXTRA_ACTION, R.string.dan_duong_den_day) == R.string.dan_duong_den_day) {
					GoogleApiController.getDirection(MainMapActivity.this, MainMapActivity.this, myLocationOverlay.getMyLocation(), new GeoPoint(data.getIntExtra(LikedLocationActivity.EXTRA_LOCATION_LAT, 0), data.getIntExtra(LikedLocationActivity.EXTRA_LOCATION_LON, 0)), Define.METHOD_NAVIGATION, Define.SENSOR);
				} else if (data.getIntExtra(LikedLocationActivity.EXTRA_ACTION, R.string.dan_duong_den_day) == R.string.show_in_map) {
					// show in map
					// if mask location
					indexTapLocationEntity = DtbLikeLocation.getLikeLocationFromId(SessionData.getDb(), data.getIntExtra(LikedLocationActivity.EXTRA_LOCATION_LAT, 0), data.getIntExtra(LikedLocationActivity.EXTRA_LOCATION_LON, 0));
					showNewLocation(indexTapLocationEntity);
				}
				break;

			default:
				break;
			}
		}
	}

	@Override
	protected boolean isRouteDisplayed() {
		return false;
	}

	/*************************************************************************************************************
	 * FUNCTION
	 *************************************************************************************************************/

	/**
	 * init Id VIew
	 */
	private void init() {
		progressDialog = new ProgressDialog(this);
		progressDialog.setCanceledOnTouchOutside(false);

		bottomDirection = (DisplayDirectionView) findViewById(R.id.bottomDirection);
		stepDisplayDirection = (StepDirectionView) findViewById(R.id.stepDisplayDirection);
		stepDisplayDirection.setDisPlayDirectionView(bottomDirection, this);
		((Button) findViewById(R.id.btnNext)).setText(R.string.menu);
		((TextView) findViewById(R.id.txtTitleBar)).setText(R.string.map);
		menuMain = (MenuMainView) findViewById(R.id.menuMain);
		layoutNavigation = (View) findViewById(R.id.formNavigation);
		layoutNavigation.setVisibility(View.GONE);
		edtEnd = (EditText) findViewById(R.id.edtEnd);
		edtStart = (EditText) findViewById(R.id.edtStart);

		// neu chua dang nhap thi an Logout o menu
		if (SessionData.getUserId().equals("")) {
			findViewById(R.id.txtLogout).setVisibility(View.GONE);
			findViewById(R.id.imgLogout).setVisibility(View.GONE);
			findViewById(R.id.txtThongBao).setVisibility(View.GONE);
			findViewById(R.id.imgThongBao).setVisibility(View.GONE);
		} else {
			findViewById(R.id.txtLogout).setVisibility(View.VISIBLE);
			findViewById(R.id.imgLogout).setVisibility(View.VISIBLE);
			findViewById(R.id.txtThongBao).setVisibility(View.VISIBLE);
			findViewById(R.id.imgThongBao).setVisibility(View.VISIBLE);
		}
	}

	/**
	 *  set data info location
	 */
	private void setDataInfoLocation() {
		// get current list location status
		LocationController.getListLocationStatus(this, this);
	}

	/**
	 *  init Ocarlay Location
	 */
	private void initOverLay() {


		// cong trinh giao thong
		itemizedOverlayUnderConstruction = new SimpleItemizedOverlay(getResources().getDrawable(R.drawable.under_construction), mapView);
		itemizedOverlayUnderConstruction.setShowClose(false);
		itemizedOverlayUnderConstruction.setShowDisclosure(true);
		itemizedOverlayUnderConstruction.setOnTapMethod(new SimpleItemizedOverlay.OnTapMethod() {

			public void onTabListener(int index, OverlayItem item) {
				showLocationStatusDialog(item,getString(R.string.road_work));
			}
		});
		
		// mat tin hieu giao thong
		itemizedOverlayTrafficLight = new SimpleItemizedOverlay(getResources().getDrawable(R.drawable.traffic_light), mapView);
		itemizedOverlayTrafficLight.setShowClose(false);
		itemizedOverlayTrafficLight.setShowDisclosure(true);
		itemizedOverlayTrafficLight.setOnTapMethod(new SimpleItemizedOverlay.OnTapMethod() {

			public void onTabListener(int index, OverlayItem item) {
				showLocationStatusDialog(item,getString(R.string.traffic_light_burtnout));
			}
		});

		// co canh sat
		itemizedOverlayPolice = new SimpleItemizedOverlay(getResources().getDrawable(R.drawable.policeman_uniform_128), mapView);
		itemizedOverlayPolice.setShowClose(false);
		itemizedOverlayPolice.setShowDisclosure(true);
		itemizedOverlayPolice.setOnTapMethod(new SimpleItemizedOverlay.OnTapMethod() {

			public void onTabListener(int index, OverlayItem item) {
				showLocationStatusDialog(item,getString(R.string.police));
			}
		});

		// co tai nan giao thong
		itemizedOverlayAccident = new SimpleItemizedOverlay(getResources().getDrawable(R.drawable.accident), mapView);
		itemizedOverlayAccident.setShowClose(false);
		itemizedOverlayAccident.setShowDisclosure(true);
		itemizedOverlayAccident.setOnTapMethod(new SimpleItemizedOverlay.OnTapMethod() {

			public void onTabListener(int index, OverlayItem item) {
				showLocationStatusDialog(item,getString(R.string.accident));
			}
		});

		// ket cung
		itemizedOverlayTrafficJams_5 = new SimpleItemizedOverlay(getResources().getDrawable(R.drawable.traffic_jams_5), mapView);
		itemizedOverlayTrafficJams_5.setShowClose(false);
		itemizedOverlayTrafficJams_5.setShowDisclosure(true);
		itemizedOverlayTrafficJams_5.setOnTapMethod(new SimpleItemizedOverlay.OnTapMethod() {

			public void onTabListener(int index, OverlayItem item) {
				showLocationStatusDialog(item, getString(R.string.jam));
			}
		});

		// di chuyen kho khan
		itemizedOverlayTrafficJams_10 = new SimpleItemizedOverlay(getResources().getDrawable(R.drawable.traffic_jams_10), mapView);
		itemizedOverlayTrafficJams_10.setShowClose(false);
		itemizedOverlayTrafficJams_10.setShowDisclosure(true);
		itemizedOverlayTrafficJams_10.setOnTapMethod(new SimpleItemizedOverlay.OnTapMethod() {

			public void onTabListener(int index, OverlayItem item) {
				showLocationStatusDialog(item, getString(R.string.very_slow));
			}
		});

		// di chuyen cham
		itemizedOverlayTrafficJams_20 = new SimpleItemizedOverlay(getResources().getDrawable(R.drawable.traffic_jams_20), mapView);
		itemizedOverlayTrafficJams_20.setShowClose(false);
		itemizedOverlayTrafficJams_20.setShowDisclosure(true);
		itemizedOverlayTrafficJams_20.setOnTapMethod(new SimpleItemizedOverlay.OnTapMethod() {

			public void onTabListener(int index, OverlayItem item) {
				showLocationStatusDialog(item,getString(R.string.slow));
			}
		});

		// di chuyen on dinh
		itemizedOverlayTrafficJams_30 = new SimpleItemizedOverlay(getResources().getDrawable(R.drawable.traffic_jams_30), mapView);
		itemizedOverlayTrafficJams_30.setShowClose(false);
		itemizedOverlayTrafficJams_30.setShowDisclosure(true);
		itemizedOverlayTrafficJams_30.setOnTapMethod(new SimpleItemizedOverlay.OnTapMethod() {

			public void onTabListener(int index, OverlayItem item) {
				showLocationStatusDialog(item, getString(R.string.normal));
			}
		});

		// thong thang
		itemizedOverlayTrafficJams_40 = new SimpleItemizedOverlay(getResources().getDrawable(R.drawable.traffic_jams_40), mapView);
		itemizedOverlayTrafficJams_40.setShowClose(false);
		itemizedOverlayTrafficJams_40.setShowDisclosure(true);
		itemizedOverlayTrafficJams_40.setOnTapMethod(new SimpleItemizedOverlay.OnTapMethod() {

			public void onTabListener(int index, OverlayItem item) {
				showLocationStatusDialog(item, getString(R.string.fast));
			}
		});



		// //////////////////////////////////////////////////////////



		// hien thi step direction tren MapView
		itemizedOverlayDirectionStep = new SimpleItemizedOverlay(getResources().getDrawable(R.drawable.navigation), mapView);
		itemizedOverlayDirectionStep.setShowClose(false);
		itemizedOverlayDirectionStep.setShowDisclosure(true);

		// hien thi start end location direction tren MapView
		itemizedOverlayDirectionStartEnd = new SimpleItemizedOverlay(getResources().getDrawable(R.drawable.start_end_navigation), mapView);
		itemizedOverlayDirectionStartEnd.setShowClose(false);
		itemizedOverlayDirectionStartEnd.setShowDisclosure(true);
		
		// three overlay New location
		itemizedOverlayNewMask = new SimpleItemizedOverlay(getResources().getDrawable(R.drawable.masker_selected), mapView);
		itemizedOverlayNewMask.setShowClose(false);
		itemizedOverlayNewMask.setShowDisclosure(true);
		
		/**
		 * set Overlay on taplistener
		 */
		itemizedOverlayNewMask.setOnTapMethod(new SimpleItemizedOverlay.OnTapMethod() {
			
			public void onTabListener(int index, OverlayItem item) {
				showNewLocationTapDialog(index);
			}
		});
		
	}


	
	
	/**************************************************************************
	 *  xem lai phan nay
	 ***************************************************************************/
	/**
	 *  set view onListener
	 */
	private void setMapViewListener() {
		
        //Add the long press listener to the map Satellite 
        mapView.setOnLongPressListener(new TapControlledMapView.onLongPressListener() {
			
			public void onLongPress(com.google.android.maps.MapView mapView,
					GeoPoint longPressLocation) {
				
				Log.d("long click", longPressLocation.getLatitudeE6()+"/"+longPressLocation.getLongitudeE6());
				if (!mask) {
					mapView.getController().animateTo(longPressLocation);

					// send message require show info location taped
					Message message = new Message();
					message.what = SEARCH_LOCATION;
					message.obj = longPressLocation;
					handler.sendMessage(message);

				}

			}
		});
		
		
		
		

		/**
		 *  dismiss balloon upon single tap of MapView (iOS behavior)
		 */
		mapView.setOnSingleTapListener(new OnSingleTapListener() {
			public boolean onSingleTap(MotionEvent e) {
				
				// hide all Ovarlay selected
				itemizedOverlayNewMask.hideAllBalloons();
				
				  if (mask) {
					// if new Overlay masked then delete this
				    itemizedOverlayNewMask.clearAll();
					mask = false;
				  }

				return true;
			}
		});
		
	}

	/********************************
	 * OnClick Method
	 *******************************/
	/**
	 * choose location from navigation
	 * 
	 * @param view
	 */
	public void onClickNavigation(View view) {
		currentViewIdNavication = view.getId();
		switch (view.getId()) {
		case R.id.btnSearchStart: {
			showDialogChooseLocationFromNavigation();
			break;
		}
		case R.id.btnSearchEnd: {
			showDialogChooseLocationFromNavigation();
			break;
		}
		case R.id.btnGo: {
			if (startLocation == null || endLocation == null || endLocation.equals(startLocation))
				break;
			String method = "";
			layoutNavigation.setVisibility(View.GONE);
			switch (((RadioGroup) findViewById(R.id.ratingRadioGroup)).getCheckedRadioButtonId()) {
			case R.id.radioDriver:
				method = "driving";
				break;
			case R.id.radioWalk:
				method = "walking";
				break;
			default:
				break;
			}
			GoogleApiController.getDirection(MainMapActivity.this, MainMapActivity.this, startLocation, endLocation, method, Define.SENSOR);
			break;
		}
		default:
			break;
		}
	}

	/**
	 * Top bar Next onClick
	 * 
	 * @param view
	 */
	public void onClickTopBarNext(View view) {
		menuMain.setVisibility(View.VISIBLE);
	}

	/**
	 * Top bar Back onClick
	 * 
	 * @param view
	 */
	public void onClickBackTopbar(View view) {
			onClickBackTopbar();
	}

	/**
	 * onClick item menu
	 * 
	 * @param view
	 */
	public void onClickItemMenu(View view) {

		menuMain.setVisibility(View.GONE);

		switch (view.getId()) {
		case R.id.txtSearch: {
			startActivityForResult(new Intent(MainMapActivity.this, SearchLocationActivity.class), REQUEST_FROM_SEARCH_LOCATION);
			break;
		}
		// gui thong bao ve vi tri hien tai
		case R.id.txtThongBao: {
			maskReportLocation = true;
			GoogleApiController.searchLocationFromGeoPoint(MainMapActivity.this, MainMapActivity.this, myLocationOverlay.getMyLocation(), Define.RADIUS_SEARCH_LOCATION, "");
			break;
		}
		// display MyLocation
		case R.id.txtCurrentLocation: {
			showMyLocation();
			break;
		}
		case R.id.txtDanDuong: {
			layoutNavigation.setVisibility(View.VISIBLE);
			break;
		}
		case R.id.txtLikeLocation: {
			startActivityForResult(new Intent(MainMapActivity.this, LikedLocationActivity.class), REQUEST_FROM_LIKE_LOCATION);
			break;
		}
		case R.id.txtSetting: {
			showDialogSetting();
			break;
		}
		case R.id.txtHelp: {
			DialogUtil.showDialog(MainMapActivity.this, getString(R.string.app_info), Html.fromHtml("Ứng dụng Traffic hỗ trợ người tham gia giao thông" + "<br>" + "Tác giả: Lý Tuấn Nam").toString(), new DialogOnClickListener() {

				public void onOKButtonOnClick() {
					// TODO nothing...
				}
			});
			break;
		}
		case R.id.txtExit: {
			break;
		}
		case R.id.txtLogout: {
			SessionData.setUserId("");
			SessionData.setUserType("");

			sharePreferenceAdapter.save(StoreAcount.USER_NAME, "");
			sharePreferenceAdapter.save(StoreAcount.PASSWORD, "");
			LoginActivity.show(MainMapActivity.this);
			break;
		}
		default:
			break;
		}
	}


	/**========================================================
	 * process response from server
	 **=========================================================
	 */
	public void onTaskComplete(HttpConnectionId requestCode, HttpResult resultCode, JSONObject result) {
		DialogUtil.showErrorDialogIfRequestFailed(this, resultCode);
		if (resultCode == HttpResult.SUCCESS) {
			switch (requestCode) {

			// response from server
			case GET_DIRECTION: {

				final ModelGetDirectionTwoLocationRequests modelGetDirectionTwoLocationRequests = new ModelGetDirectionTwoLocationRequests(result);

				// ve diem khoi dau
				itemizedOverlayDirectionStartEnd.clearAll();
				showInfoLocationMask(modelGetDirectionTwoLocationRequests.getStartLocation(), modelGetDirectionTwoLocationRequests.getStartAddress(), "", itemizedOverlayDirectionStartEnd);
				showInfoLocationMask(modelGetDirectionTwoLocationRequests.getEndLocation(), modelGetDirectionTwoLocationRequests.getEndAddress(), "", itemizedOverlayDirectionStartEnd);

				// ve duong di
				mapOverlay = new MapOverlayDrawLine(modelGetDirectionTwoLocationRequests.getStepPoint(), mapView);
				mapOverlays.add(mapOverlay);
				mapView.invalidate();
				ALog.d("so size", modelGetDirectionTwoLocationRequests.getStepPoint().size() + ":");

				// hien thi ket qua
				bottomDirection.setData(modelGetDirectionTwoLocationRequests.getStartAddress(), modelGetDirectionTwoLocationRequests.getEndAddress(), modelGetDirectionTwoLocationRequests.getDistance().getText(), modelGetDirectionTwoLocationRequests.getDuration().getText());
				bottomDirection.setVisibility(View.VISIBLE);


				// hien thi step direction
				stepDisplayDirection.setData(modelGetDirectionTwoLocationRequests, new StepDirectionView.StepOnclick() {
					public void stepOnclick(int currentDisplay) {
						// xu ly hien thi icon len map khi click step
                        if(currentDisplay == -1){
							// hien thi diem khoi dau
							itemizedOverlayDirectionStep.clearAll();
							showInfoLocationMask(modelGetDirectionTwoLocationRequests.getStartLocation(), "", "", itemizedOverlayDirectionStep);
							animationToLocation(modelGetDirectionTwoLocationRequests.getStartLocation());
						} else {
							// hien thi cac step tiep theo
							itemizedOverlayDirectionStep.clearAll();
							showInfoLocationMask(modelGetDirectionTwoLocationRequests.getStep().get(currentDisplay).getEndLocation(), "", "", itemizedOverlayDirectionStep);
							animationToLocation(modelGetDirectionTwoLocationRequests.getStep().get(currentDisplay).getEndLocation());
						}
					}
				});
				stepDisplayDirection.setVisibility(View.VISIBLE);
				animationToLocation(modelGetDirectionTwoLocationRequests.getStartLocation());
				break;
			}

			case GET_LIST_LOCATION_STATUS: {
				ModelGetListLocationStatusRequest modelGetListLocationStatusRequest = new ModelGetListLocationStatusRequest(result);
				if (modelGetListLocationStatusRequest.getCode() == Define.CODE_SUCCESSFULL) {
					// TODO... show list location status
					ArrayList<LocationStatus> locationStatus = modelGetListLocationStatusRequest.getLocationStatus();
					ALog.d("status", locationStatus.get(0) + "");
					for (int i = 0; i < locationStatus.size(); i++) {
						showLocationStatus(locationStatus.get(i));
					}
				} else {
					ToastUtils.showToast(MainMapActivity.this, R.string.error);
				}
				break;
			}
			case SEND_LOCATION_STATUS:{
				ModelSendLocationStatusRequest modelSendLocationStatusRequest = new ModelSendLocationStatusRequest(result);
				if (modelSendLocationStatusRequest.getCode() == Define.CODE_SUCCESSFULL) {
					ToastUtils.showToast(MainMapActivity.this, R.string.sended);
					// neu update location
					if (isUpdateLocationStatus) {
						MainMapActivity.show(MainMapActivity.this);
					} else {
						// neu la gui thong tin giao thong
					showLocationStatus(modelSendLocationStatusRequest.getLocationStatus());
					mapView.getController().animateTo(modelSendLocationStatusRequest.getLocationStatus().getGeoPoint());
					}
				} else {
					ToastUtils.showToast(MainMapActivity.this, R.string.error);
				}
				break;
			}
			case GET_LOCATION_INFO_REQUEST:{
				modelGetLocationInfoGoogleApiRequest = new ModelGetLocationInfoGoogleApiRequest(result);
				if (modelGetLocationInfoGoogleApiRequest.getStatus().equals("OK")) {
					showDialogListLocation();

				} else {
					ToastUtils.showToast(MainMapActivity.this, R.string.error);
				}
				break;
			}
			// default
			default: {
				// do nothing
				break;
			}
			} // end switch
		}
	}

	/**
	 * show location status
	 * 
	 * @param locationStatus
	 */
	private void showLocationStatus(LocationStatus locationStatus) {
		switch (locationStatus.getStatus()) {
		case LocationStatus.TAI_NAN_GIAO_THONG: {
			showInfoLocationMask(locationStatus.getGeoPoint(), locationStatus.getInfoName(), locationStatus.getUserPostId(), itemizedOverlayAccident);
			break;
		}
		case LocationStatus.CO_CANH_SAT: {
			showInfoLocationMask(locationStatus.getGeoPoint(), locationStatus.getInfoName(), locationStatus.getUserPostId(), itemizedOverlayPolice);
			break;
		}
		case LocationStatus.CONG_TRINH_GIAO_THONG: {
			showInfoLocationMask(locationStatus.getGeoPoint(), locationStatus.getInfoName(), locationStatus.getUserPostId(), itemizedOverlayUnderConstruction);
			break;
		}
		case LocationStatus.MAT_TIN_HIEU_GIAO_THONG: {
			showInfoLocationMask(locationStatus.getGeoPoint(), locationStatus.getInfoName(), locationStatus.getUserPostId(), itemizedOverlayTrafficLight);
			break;
		}
		case LocationStatus.KET_CUNG: {
			showInfoLocationMask(locationStatus.getGeoPoint(), locationStatus.getInfoName(), locationStatus.getUserPostId(), itemizedOverlayTrafficJams_5);
			break;
		}
		case LocationStatus.DI_CHUYEN_KHO_KHAN: {
			showInfoLocationMask(locationStatus.getGeoPoint(), locationStatus.getInfoName(), locationStatus.getUserPostId(), itemizedOverlayTrafficJams_10);
			break;
		}
		case LocationStatus.DI_CHUYEN_CHAM: {
			showInfoLocationMask(locationStatus.getGeoPoint(), locationStatus.getInfoName(), locationStatus.getUserPostId(), itemizedOverlayTrafficJams_20);
			break;
		}
		case LocationStatus.DI_CHUYEN_ON_DINH: {
			showInfoLocationMask(locationStatus.getGeoPoint(), locationStatus.getInfoName(), locationStatus.getUserPostId(), itemizedOverlayTrafficJams_30);
			break;
		}
		case LocationStatus.THONG_THOANG: {
			showInfoLocationMask(locationStatus.getGeoPoint(), locationStatus.getInfoName(), locationStatus.getUserPostId(), itemizedOverlayTrafficJams_40);
			break;
		}
		default:
			break;
		}
	}
	
	/**
	 * mask location info
	 * 
	 * @param geoPoint
	 * @param title
	 * @param snippet
	 * @param simpleItemizedOverlay
	 */
	public void showInfoLocationMask(GeoPoint geoPoint, String title, String snippet, SimpleItemizedOverlay simpleItemizedOverlay) {
		OverlayItem overlayItem = new OverlayItem(geoPoint, title, getString(R.string.source) + " " + (snippet.matches("((-|\\+)?[0-9]+(\\.[0-9]+)?)+") ? "Người dùng" : snippet));
		simpleItemizedOverlay.addOverlay(overlayItem);

		mapOverlays.add(simpleItemizedOverlay);
		mapView.invalidate();
	}
	
	/**
	 *  show my location
	 */
	public void showMyLocation() {

		mapOverlays.add(myLocationOverlay);// Add the overlay
		myLocationOverlay.runOnFirstFix(new Runnable() {

			public void run() {
				animationToLocation(myLocationOverlay.getMyLocation());
			}
		});
	}

	/**
	 * hien thi thong tin giao thong dia diem
	 */
	public void showLocationStatusDialog(final OverlayItem overlayItem, String locationStatus) {

		String title = getString(R.string.traffic_status);

		if (SessionData.getUserType().equals(Define.COLLABOATOR)) {
			title = getString(R.string.update_traffic_status);
		}
		DialogUtil.showConfirmDialog(MainMapActivity.this, title, Html.fromHtml(getString(R.string.address) + ": " + overlayItem.getTitle() + "<br>" + getString(R.string.status) + " " + locationStatus + "<br>" + overlayItem.getSnippet()).toString(), new DialogUtil.ConfirmDialogOnClickListener() {

			public void onOKButtonOnClick() {
				if (SessionData.getUserType().equals(Define.COLLABOATOR)) {
					isUpdateLocationStatus = true;
					showDialogReportLocationStatus(overlayItem.getPoint(), overlayItem.getTitle(), overlayItem.getSnippet());
				}
			}

			public void onCancelButtonOnClick() {
				// nothing...
			}
		});
	}

	/**
	 * show dialog when click new location
	 */
	protected void showNewLocationTapDialog(int index) {
		final int indexSelect = index;

		ArrayList<Integer> selects = new ArrayList<Integer>();
		selects.add(Integer.valueOf(R.string.dan_duong_den_day));
		selects.add(Integer.valueOf(R.string.them_vao_danh_sach_yeu_thich));

		if (SessionData.getUserType().equals(Define.COLLABOATOR)) {
			ALog.d("vao", "vao");
			selects.add(Integer.valueOf(R.string.thong_bao));
		}
		int[] select = new int[selects.size()];
		for (int i = 0; i < selects.size(); i++) {
			select[i] = selects.get(i).intValue();
		}

		final int DAN_DUONG = 0;
		final int THEM_DS_YEU_THICH = 1;
		final int REPORT = 2;
		DialogUtil.showListDialog(this, R.string.diem_danh_dau, select, new DialogInterface.OnClickListener() {
			public void onClick(DialogInterface dialog, int which) {
				switch (which) {
				// select dan duong
				case DAN_DUONG: {
					ALog.d("dan duong", "dan duong");
					// dan duong tu vi tri hien tai den diem lua chon
					GoogleApiController.getDirection(MainMapActivity.this, MainMapActivity.this, myLocationOverlay.getMyLocation(), itemizedOverlayNewMask.getItem(indexSelect).getPoint(), Define.METHOD_NAVIGATION, Define.SENSOR);
					break;
				}
				// them vao danh sach yeu thich
				case THEM_DS_YEU_THICH: {
					// store in database
					DtbLikeLocation.insertToDatabase(SessionData.getDb(), indexTapLocationEntity);
					ALog.d("ds", "ds" + itemizedOverlayNewMask.getItem(indexSelect).getTitle() + indexTapLocationEntity.getAddress());
					break;
				}
				// thong bao thong tin dia diem chi co voi cong tac vien
				case REPORT: {
					isUpdateLocationStatus = false;
					showDialogReportLocationStatus(itemizedOverlayNewMask.getItem(indexSelect).getPoint(), itemizedOverlayNewMask.getItem(indexSelect).getTitle(), itemizedOverlayNewMask.getItem(indexSelect).getSnippet());
					break;
				}
				default:

					break;
				}
				// xoa bo diem da chon
				// hide all Ovarlay selected
				itemizedOverlayNewMask.hideAllBalloons();

				if (mask) {
					// if new Overlay masked then delete this
					itemizedOverlayNewMask.clearAll();
					mask = false;
				}

			}
		});
	}

	/**
	 * show dialog report location status
	 * 
	 * @param location
	 */
	public void showDialogReportLocationStatus(final GeoPoint location, final String nameLocation, final String addressLocation) {

		// hide all Ovarlay selected
		itemizedOverlayNewMask.hideAllBalloons();

		AlertDialog.Builder builder = new AlertDialog.Builder(MainMapActivity.this);
		builder.setTitle(R.string.report);

		// set content Dialog
		LayoutInflater inflater = getLayoutInflater();
		View dialoglayout = inflater.inflate(R.layout.layout_dialog_send_status_location, null);

		builder.setView(dialoglayout);
		builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
			
			public void onClick(DialogInterface dialog, int which) {
				
			}
		});
		final Dialog dialogSelect = builder.create();

		View.OnClickListener onClickListener = new View.OnClickListener() {

			public void onClick(View v) {
				dialogSelect.dismiss();
				int n = 0;
				switch (v.getId()) {
				case R.id.btnRoadWork: {
                     n = 0;
					break;
				}
				case R.id.btnTrafficLight: {
					n = 1;
					break;
				}
				case R.id.btnPolice: {
					n = 2;
					break;
				}
				case R.id.btnAccident: {
					n = 3;
					break;
				}
				case R.id.btnTrafficJams_5: {
					n = 4;
					break;
				}
				case R.id.btnTrafficJams_10: {
					n = 5;
					break;
				}
				case R.id.btnTrafficJams_20: {
					n = 6;
					break;
				}
				case R.id.btnTrafficJams_30: {
					n = 7;
					break;
				}
				case R.id.btnTrafficJams_40: {
					n = 8;
					break;
				}
				default:
					break;
				}
				// neu chon thong bao
				LocationController.sendLocationStatus(MainMapActivity.this, MainMapActivity.this, location, n, SessionData.getUserId().equals("") ? "-1" : SessionData.getUserId(), nameLocation, addressLocation);
			}
		};

		dialoglayout.findViewById(R.id.btnRoadWork).setOnClickListener(onClickListener);
		dialoglayout.findViewById(R.id.btnTrafficLight).setOnClickListener(onClickListener);
		dialoglayout.findViewById(R.id.btnPolice).setOnClickListener(onClickListener);
		dialoglayout.findViewById(R.id.btnAccident).setOnClickListener(onClickListener);
		dialoglayout.findViewById(R.id.btnTrafficJams_5).setOnClickListener(onClickListener);
		dialoglayout.findViewById(R.id.btnTrafficJams_10).setOnClickListener(onClickListener);
		dialoglayout.findViewById(R.id.btnTrafficJams_20).setOnClickListener(onClickListener);
		dialoglayout.findViewById(R.id.btnTrafficJams_30).setOnClickListener(onClickListener);
		dialoglayout.findViewById(R.id.btnTrafficJams_40).setOnClickListener(onClickListener);

		dialogSelect.show();

	}

	/**
	 * show dialog choose location
	 * 
	 * @param viewId
	 */
	public void showDialogChooseLocationFromNavigation() {
		int select[] = { R.string.current_location, R.string.select_map_location, R.string.like_location };

		DialogUtil.showListDialog(this, R.string.select, select, new DialogInterface.OnClickListener() {
			public void onClick(DialogInterface dialog, int which) {
				// neu chon thong bao
				switch (which) {
				case 0: {
					if (currentViewIdNavication == R.id.btnSearchStart) {
						startLocation = myLocationOverlay.getMyLocation();
						edtStart.setText(R.string.current_location);
					} else {
						endLocation = myLocationOverlay.getMyLocation();
						edtEnd.setText(R.string.current_location);
					}
					break;
				}
				// select from point in map
				case 1: {
					layoutNavigation.setVisibility(View.GONE);
					maskNavigation = true;
					break;
				}
				// select from liked location
				case 2: {
					ArrayList<LocationSearchEntity> arrayList = new ArrayList<LocationSearchEntity>();
					String selectQuery = "SELECT * FROM " + DtbLikeLocation.TABLE_LIKE_LOCATION;
					arrayList.addAll(DtbLikeLocation.querySelect(SessionData.getDb(), selectQuery));
					showDlialogListLikedLocation(arrayList);
					break;
				}
				default:
					break;
				}

			}
		});
	}
	
	/**
	 * show listLocation
	 */
	private void showDialogListLocation(){
		AlertDialog.Builder builder = new AlertDialog.Builder(MainMapActivity.this);
		builder.setTitle(R.string.confirm).setCancelable(false).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {

			public void onClick(DialogInterface dialog, int which) {
				maskReportLocation = false;
			}
		});
		
		ListView modeList = new ListView(MainMapActivity.this);
		modeList.setBackgroundColor(getResources().getColor(R.color.white));
		ListLocationAdapter modeAdapter = new ListLocationAdapter(MainMapActivity.this, android.R.layout.simple_list_item_1, modelGetLocationInfoGoogleApiRequest.getLocationStatus());
		modeList.setAdapter(modeAdapter);

		builder.setView(modeList);
		final Dialog dialogSelect = builder.create();

		modeList.setOnItemClickListener(new ListView.OnItemClickListener() {
			public void onItemClick(AdapterView<?> a, View v, int i, long l) {
				dialogSelect.dismiss();

				// if report location
				if (maskReportLocation) {
					maskReportLocation = false;
					isUpdateLocationStatus = false;
					showDialogReportLocationStatus(modelGetLocationInfoGoogleApiRequest.getLocationStatus().get(i).getGeoPoint(), modelGetLocationInfoGoogleApiRequest.getLocationStatus().get(i).getName(), modelGetLocationInfoGoogleApiRequest.getLocationStatus().get(i).getAddress());
				} else if (maskNavigation) {
					// set navigation location
					maskNavigation = false;
					layoutNavigation.setVisibility(View.VISIBLE);
					if (currentViewIdNavication == R.id.btnSearchStart) {
						startLocation = modelGetLocationInfoGoogleApiRequest.getLocationStatus().get(i).getGeoPoint();
						edtStart.setText(modelGetLocationInfoGoogleApiRequest.getLocationStatus().get(i).getName());
					} else {
						endLocation = modelGetLocationInfoGoogleApiRequest.getLocationStatus().get(i).getGeoPoint();
						edtEnd.setText(modelGetLocationInfoGoogleApiRequest.getLocationStatus().get(i).getName());
					}
				} else {
					// if mask location
					showNewLocation(modelGetLocationInfoGoogleApiRequest.getLocationStatus().get(i));
					indexTapLocationEntity = modelGetLocationInfoGoogleApiRequest.getLocationStatus().get(i);
				}
			}
		});

		dialogSelect.show();
	}

	/**
	 * show new mask location
	 * 
	 * @param locationSearchEntity
	 */
	private void showNewLocation(LocationSearchEntity locationSearchEntity) {
		// if mask location
		OverlayItem overlayItem = new OverlayItem(locationSearchEntity.getGeoPoint(), locationSearchEntity.getName(), locationSearchEntity.getAddress());
		itemizedOverlayNewMask.addOverlay(overlayItem);
		// send message require show info location taped
		Message message = new Message();
		message.what = SHOW_TAP_LOCATION;
		handler.sendMessage(message);
		mask = true;
	}

	/**
	 * show listLocation
	 */
	private void showDlialogListLikedLocation(final ArrayList<LocationSearchEntity> arrayList) {
		AlertDialog.Builder builder = new AlertDialog.Builder(MainMapActivity.this);
		builder.setTitle(R.string.like_location).setCancelable(false).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {

			public void onClick(DialogInterface dialog, int which) {

			}
		});

		ListView modeList = new ListView(MainMapActivity.this);
		modeList.setBackgroundColor(getResources().getColor(R.color.white));

		ListLocationAdapter modeAdapter = new ListLocationAdapter(MainMapActivity.this, android.R.layout.simple_list_item_1, arrayList);
		modeList.setAdapter(modeAdapter);

		builder.setView(modeList);
		final Dialog dialogSelect = builder.create();

		modeList.setOnItemClickListener(new ListView.OnItemClickListener() {
			public void onItemClick(AdapterView<?> a, View v, int i, long l) {
				dialogSelect.dismiss();
				if (currentViewIdNavication == R.id.btnSearchStart) {
					startLocation = arrayList.get(i).getGeoPoint();
					edtStart.setText(arrayList.get(i).getName());
				} else {
					endLocation = arrayList.get(i).getGeoPoint();
					edtEnd.setText(arrayList.get(i).getName());
				}
			}
		});

		dialogSelect.show();
	}

	/**
	 * show Setting Map
	 */
	private void showDialogSettingMap() {
		AlertDialog.Builder builder = new AlertDialog.Builder(MainMapActivity.this);
		builder.setTitle(R.string.setting_map);

		// set content Dialog
		LayoutInflater inflater = getLayoutInflater();
		View dialoglayout = inflater.inflate(R.layout.layout_dialog_setting_map, null);
		final CheckBox cbxStreetMap = (CheckBox) dialoglayout.findViewById(R.id.cbxStreetMap);
		final CheckBox cbxTrafficMap = (CheckBox) dialoglayout.findViewById(R.id.cbxTrafficMap);
		final CheckBox cbxSateMap = (CheckBox) dialoglayout.findViewById(R.id.cbxSateMap);

		cbxSateMap.setChecked(SessionData.isSatellite());
		cbxStreetMap.setChecked(SessionData.isStreet());
		cbxTrafficMap.setChecked(SessionData.isTraffic());

		builder.setView(dialoglayout);
		builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {

			public void onClick(DialogInterface dialog, int which) {

			}
		}).setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {

			public void onClick(DialogInterface dialog, int which) {
				SessionData.setStreet(cbxStreetMap.isChecked());
				SessionData.setTraffic(cbxTrafficMap.isChecked());
				SessionData.setSatellite(cbxSateMap.isChecked());
				setDisplayMap();
			}
		});

		final Dialog dialogSelect = builder.create();
		dialogSelect.show();
	}

	/**
	 * cai dat dinh vu vi tri
	 */
	private void showDialogSettingLocationService() {
		AlertDialog.Builder builder = new AlertDialog.Builder(MainMapActivity.this);
		builder.setTitle(R.string.setting_location_service);

		// set content Dialog
		LayoutInflater inflater = getLayoutInflater();
		View dialoglayout = inflater.inflate(R.layout.layout_dialog_setting_location, null);
		final RadioButton ratioGps = (RadioButton) dialoglayout.findViewById(R.id.ratioGps);
		final RadioButton ratioNetwork = (RadioButton) dialoglayout.findViewById(R.id.ratioNetwork);

		ratioGps.setChecked(SessionData.isGPS());
		ratioNetwork.setChecked(SessionData.isNetwork());
		ratioGps.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
			
			public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
				ratioNetwork.setChecked(!isChecked);
			}
		});
		ratioNetwork.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

			public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
				ratioGps.setChecked(!isChecked);
			}
		});

		builder.setView(dialoglayout);
		builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {

			public void onClick(DialogInterface dialog, int which) {

			}
		}).setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {

			public void onClick(DialogInterface dialog, int which) {
				SessionData.setGPS(ratioGps.isChecked());
				SessionData.setNetwork(ratioNetwork.isChecked());
				myLocationOverlay.enableMyLocation();
				if (SessionData.isGPS() && !myLocationOverlay.getmLocationManager().isProviderEnabled(LocationManager.GPS_PROVIDER)) {
					showSettingsAlert();
				}
			}
		});

		final Dialog dialogSelect = builder.create();
		dialogSelect.show();
	}

	/**
	 * show dialog setting
	 */
	public void showDialogSetting() {
		int select[] = { R.string.setting_map, R.string.setting_location_service };

		DialogUtil.showListDialog(this, R.string.select, select, new DialogInterface.OnClickListener() {
			public void onClick(DialogInterface dialog, int which) {
				// cai dat hien thi map
				switch (which) {
				case 0: {
					showDialogSettingMap();
					break;
				}
				// cai dat dich vu vi tri
				case 1: {
					showDialogSettingLocationService();
					break;
				}
				default:
					break;
				}

			}
		});
	}

	/**
	 * Function to show settings alert dialog On pressing Settings button will
	 * lauch Settings Options
	 */
	public void showSettingsAlert() {
		AlertDialog.Builder alertDialog = new AlertDialog.Builder(this);

		// Setting Dialog Title
		alertDialog.setTitle("GPS is settings");

		// Setting Dialog Message
		alertDialog.setMessage("GPS is not enabled. Do you want to go to settings menu?");

		// On pressing Settings button
		alertDialog.setPositiveButton("Settings", new DialogInterface.OnClickListener() {
			public void onClick(DialogInterface dialog, int which) {
				Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
				startActivity(intent);
			}
		});

		// on pressing cancel button
		alertDialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
			public void onClick(DialogInterface dialog, int which) {
				dialog.cancel();
			}
		});
		// Showing Alert Message
		alertDialog.show();
	}

	/**
	 * hien thi den dia diem
	 */
	private void animationToLocation(GeoPoint geoPoint) {
		mapView.getController().animateTo(geoPoint);
		mapView.getController().setZoom(Define.ZOOM_MAP);// Set the zoom
	}

	/**
	 * call this Activity
	 * 
	 * @param context
	 */
	public static void show(Context context) {
		Intent intent = new Intent(context, MainMapActivity.class);
		context.startActivity(intent);
	}

	/**
	 * show dialog
	 * 
	 * @param resMessage
	 */
	public void showDialogMessage(int resMessage) {
		progressDialog.setTitle("");
		progressDialog.setMessage(getString(resMessage));
		progressDialog.show();
	}

	/**
	 * close dialog
	 */
	public void closeDialogMessage() {
		progressDialog.dismiss();
	}

}